package com.jz.pay3.design.observer;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Teacher implements Subject{

    private String name;

    private Object tel;

    private List<Observer> students = new ArrayList<>();

    public Teacher(String name, Object tel) {
        this.name = name;
        this.tel = tel;
    }

    @Override
    public Object getUpdate() {
        return tel;
    }

    @Override
    public void addObserver(Observer observer) {
        students.add(observer);
        observer.update();
    }

    @Override
    public void rmObserver(Observer observer) {
        students.remove(observer);
        observer.update();
    }

    @Override
    public void modify(Object obj) {
        this.tel = obj;
        for (Observer student : students) {
            student.update();
        }
    }


}
